<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta charset="utf-8">
    <title>工具管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pagination.css">
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/js/pagination.js"></script>
    <script src="${pageContext.request.contextPath}/js/my.js"></script>
</head>
<body class="hold-transition skin-red sidebar-mini">
<!--数据展示头部-->
<div class="box-header with-border">
    <h3 class="box-title">工具</h3>
</div>
<!--数据展示头部-->
<!--数据展示内容区-->
<div class="box-body">
    <!-- 数据表格 -->
    <table id="dataList" class="table table-bordered table-striped table-hover dataTable text-center">
        <thead>
        <tr>
            <th class="sorting_asc">工具名称</th>
            <th class="sorting">工具数量</th>
            <th class="sorting">工具状态</th>
            <th class="sorting">借用人</th>
            <th class="sorting">借用时间</th>
            <th class="sorting">归还时间</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${pageResult}" var="tool">
            <tr>
                <td> ${tool.name}</td>
                <td>${tool.pagination}</td>
                <td>
                    <c:if test="${tool.status ==0}">可借用</c:if>
                    <c:if test="${tool.status ==1}">借用中</c:if>
                    <c:if test="${tool.status ==2}">归还中</c:if>
                </td>
                <td>${tool.borrower}</td>
                <td>${tool.borrowtime}</td>
                <td>${tool.returntime}</td>
                <td class="text-center">
                    <c:if test="${tool.status ==0}">
                        <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#borrowModal"
                                onclick="findBookById(${tool.id},'borrow')"> 借用
                        </button>
                    </c:if>
                    <c:if test="${tool.status ==1 ||tool.status ==2}">
                        <button type="button" class="btn bg-olive btn-xs" disabled="true">借用</button>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <button type="button" class="btn bg-olive btn-xs" onclick="prePage(${pageNum},${pages})">上一页</button>&nbsp;${pageNum}&nbsp;
    <button type="button" class="btn bg-olive btn-xs" onclick="nextPage(${pageNum},${pages})">下一页</button>
    <!-- 数据表格 /-->
</div>
<!-- 数据展示内容区/ -->
<%--引入存放模态窗口的页面--%>
<jsp:include page="/admin/tool_modal.jsp"></jsp:include>
<script>
    function prePage(index,pages) {
        if(index>1) index=index-1;
        else index=1;
        var url="/selectPageByIndex?index="+index;
        $.get(url,function (response) {
            console.log(response);
        });
    }
    function nextPage(index,pages) {
        if(index>=pages) index=pages;
        else index=index+1;
        var url="/selectPageByIndex?index="+index;
        $.get(url,function (response) {
            console.log(response);
        });
    }

</script>
</body>
</html>
